import request from "@/utils/request";
import {
    QueryParams,
    QueryRes,
    SaveParams,
    SaveRes,
    DeleteRes,
    QueryArrayRes,
    GenTrainSeatRes
} from "@/api/base/train/type.ts";

/**
 * 删除列车信息
 * @param {string} id
 * @returns
 */
export function deleteById(id: number): Promise<DeleteRes> {
    return request.delete(`/business/admin/train/delete/${id}`);
}

/**
 * 保存列车信息或编辑
 * @param {object} params TrainSaveReq
 * @param {number} params.id
 * @param {string} params.code
 * @param {string} params.type
 * @param {string} params.start
 * @param {string} params.startPinyin
 * @param {object} params.startTime
 * @param {string} params.end
 * @param {string} params.endPinyin
 * @param {object} params.endTime
 * @param {object} params.createTime
 * @param {object} params.updateTime
 * @returns
 */
export function save(params: SaveParams): Promise<SaveRes> {
    return request.post(`/business/admin/train/save`, params);
}

/**
 * 查询列车列表
 * @param {object} params TrainQueryReq
 * @param {number} params.pageNum
 * @param {number} params.pageSize
 * @returns
 */
export function query(params: QueryParams): Promise<QueryRes> {
    return request.post(`/business/admin/train/quest-list`, params);
}

/**
 * 查询列车列表
 * @returns
 */
export function queryAll(): Promise<QueryArrayRes> {
    return request.get(`/business/admin/train/quest-all`);
}

/**
 * 生成车次座位
 * @param {string} trainCode
 * @returns
 */
export function genTrainSeat(trainCode: string): Promise<GenTrainSeatRes> {
    return request.get(`/business/admin/train/gen-seat/${trainCode}`);
}

/**
 * 生成每日车次
 * @param {string} date
 * @returns
 */
export function genDaily(date: any): Promise<SaveRes> {
    return request.get(`/business/admin/dailyTrain/gen-daily/${date}`);
}